$ () ->

	_name = () ->
		if $("#name").val() is '' || $("#name").val() is null
			return ""
		else
			return '&name=' + $("#name").val()
	_sex = () ->
		if $('input:radio[name="sex"]:checked').val() is '' || $('input:radio[name="sex"]:checked').val() is null || $('input:radio[name="sex"]:checked').val() is undefined
			return ""
		else
			return '&sex=' + $('input:radio[name="sex"]:checked').val()

	_caseType = () ->
		if $("#case_type").val() is '' || $("#case_type").val() is null
			return ""
		else
			return '&case_type=' + $("#case_type").val()

	_province = () ->
		if $("#province").val() is '' || $("#province").val() is null 
			return ""
		else
			return '&province_id=' + $("#province").val()

	$("#select_btn").click (e) ->
		# console.log "/admin/case/list?" + _name() + _sex() + _caseType() + _province()
		window.location.href = "/admin/case/list?" + _name() + _sex() + _caseType() + _province()

	$("#clean_btn").click (e) ->
		$("#name").val("")
		$('input:radio[name="sex"]').removeAttr('checked')
		$($("#province").children().eq(0).attr('selected','selected'))
		$($("#case_type").children().eq(0).attr('selected','selected'))


	$(".delete_btn").click (e) ->
		param =
			id: $(e.target).parent().parent().children().eq(0).text()

		$.post "/api/admin/case/delete" ,param ,(res) ->
			if res.status.errCode is 0
				alert "删除成功"
				location.reload()
			else
				alert res.status.message